Conversation
Signed-off-by: Florent MILLOT <millotflo@gmail.com>
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
If you create AnnouncementController then you can connect AnnoucementController and AnnouncementService directly
| @Test | ||
| void testGetAllMaintenanceMessages() throws Exception { | ||
| announcementRepository.save(new AnnouncementEntity("I think dangling line is a funny name for a line", Duration.ofSeconds(60))); | ||
| assertEquals(1, announcementRepository.findAll().size()); | ||
|
|
||
| // Try to retrieve all the messages and expect everything to be ok | ||
| MvcResult mvcResult = mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/announcements") | ||
| .header("userId", ADMIN_USER)) | ||
| .andExpect(status().isOk()).andReturn(); | ||
| List<AnnouncementEntity> announcements = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { | ||
| }); | ||
| assertEquals(1, announcements.size()); | ||
|
|
||
| // Try to retrieve all the messages with a user that's not an admin and expect 403 FORBIDDEN | ||
| mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/announcements") | ||
| .header("userId", NOT_ADMIN)) | ||
| .andExpect(status().isForbidden()); | ||
| } |
There was a problem hiding this comment.
Can you separete the tests for OK results and for forbidden ?
There was a problem hiding this comment.
I just updated and completed the test, I prefer to keep them like it was (TL already told me few times to change only the necessary so that's what I do now)
| @Test | ||
| public void testCancelMaintenanceMessage() throws Exception { | ||
| AnnouncementEntity announcement = announcementRepository.save(new AnnouncementEntity("I think dangling line is a funny name for a line", Duration.ofSeconds(60))); | ||
| assertEquals(1, announcementRepository.findAll().size()); | ||
|
|
||
| //Send a cancel maintenance message and expect everything to be ok | ||
| mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/messages/cancel-maintenance") | ||
| mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + announcement.getId()) | ||
| .header("userId", ADMIN_USER)) | ||
| .andExpect(status().isOk()); | ||
| assertCancelMaintenanceMessageSent(); | ||
| assertEquals(0, announcementRepository.findAll().size()); | ||
|
|
||
| // With a non-existing ID, expect 404 | ||
| mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + UUID.randomUUID()) | ||
| .header("userId", ADMIN_USER)) | ||
| .andExpect(status().isNotFound()); | ||
|
|
||
| //Send a cancel maintenance message with a user that's not an admin and expect 403 FORBIDDEN | ||
| mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/messages/cancel-maintenance") | ||
| mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + UUID.randomUUID()) | ||
| .header("userId", NOT_ADMIN)) | ||
| .andExpect(status().isForbidden()); | ||
| } |
| if (announcement.getDuration() == null) { | ||
| notificationService.emitMaintenanceMessage(announcement.getMessage()); | ||
| } else { | ||
| notificationService.emitMaintenanceMessage(announcement.getMessage(), announcement.getDuration().toSeconds()); | ||
| } |
There was a problem hiding this comment.
Maybe this can be handled in the EmitMessage method
There was a problem hiding this comment.
I would have done that also, but it's not a big deal and does not change that much so I kept the existing code
Signed-off-by: Florent MILLOT <millotflo@gmail.com>
|
Signed-off-by: Abdelsalem <abdelsalem.hedhili@rte-france.com>
|



No description provided.